home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_02 / smith / crc16.h < prev    next >
C/C++ Source or Header  |  1993-12-29  |  709b  |  26 lines

  1. /* CRC16.H
  2.  *
  3.  * Use updcrc() for a block of data,
  4.  *   UPDATE_CRC1() for a single byte.
  5.  *
  6.  * Adapted from CRC-16F.C, a public domain routine
  7.  * in Bob Stout's Snippets file collection.
  8.  * Adaptations donated to public domain.
  9. */
  10.  
  11. #define CRCW 16             /* # bits in CRC */
  12. #define CRCLBY  (CRCW/8)    /* CRC byte length */
  13. #define CRCMASK ((1U<<CRCW)-1) /* mask for full CRC */
  14.  
  15. extern unsigned short crctab[1 << 8];
  16.  
  17. void initcrctab(void);  /* Initialize CRC table */
  18. unsigned short updcrc(unsigned short icrc,
  19.     const unsigned char *icp, unsigned int icnt);
  20.  
  21. #define UPDATE_CRC1(c,crc) (((crc)<<8) ^ \
  22.         crctab[(((crc)>>(CRCW-8)) ^ (c)) & 0xff])
  23.  
  24. /* End of File */ 
  25.  
  26.